package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.model.AuctionTransRecord;
import com.bdsy.business.service.AuctionTransRecordService;
import com.bdsy.common.utils.Result;

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class AuctionTransRecordController {

	@Autowired
	private AuctionTransRecordService auctionTransRecordService;
	
	/**
	 * 
	    * @Title: add
	    * @Description: 添加竞拍信息
	 */
	@IgnoreAuth
	@RequestMapping("/addAuctionTransRecord")
	@ResponseBody
	public Object addAuctionTransRecord(AuctionTransRecord auctionTransRecord) {
		boolean result = auctionTransRecordService.addAuctionTransRecord(auctionTransRecord);
		if (result) {
			return Result.ok("addSuccess");
		} else {
			return Result.error("addFail");
		}
	}
	
	/**
	 *  
	 *  （没用）
	    * @Title: numberRecord
	    * @Description: 参拍人数  竞拍记录
	 */
	@RequestMapping("/numberRecord")
	@ResponseBody
	public Object numberRecord(int shopId) {
		//参拍人数
		int totalCount = auctionTransRecordService.count(shopId);
		// 竞拍记录
		List<Map> auctionTransRecord =  auctionTransRecordService.selectAuctionTransRecordByShopId(shopId);
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("totalCount", totalCount);
		map.put("auctionTransRecord", auctionTransRecord);
		return map;
	}
	
	/**
	 * 
	    * @Title: selectAuctionTransRecordByUserId
	    * @Description: 参拍物品
	 */
	@IgnoreAuth
	@RequestMapping("/auctionTransRecordList")
	@ResponseBody
	public Object selectAuctionTransRecordByUserId(String userId) {
		@SuppressWarnings("rawtypes")
		List<Map> auctionTransRecordList =	auctionTransRecordService.selectAuctionTransRecordByUserId(userId);
		
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("auctionTransRecordList", auctionTransRecordList);
		return map;
	}
	
	/**
	 * 
	    * @Title: selectAuctionTransRecordByUserId
	    * @Description: 拍得物品
	 */
	@IgnoreAuth
	@RequestMapping("/auctionTransRecordByUserId")
	@ResponseBody
	public Object auctionTransRecordByUserId(String userId) {
		@SuppressWarnings("rawtypes")
		List<Map> auctionTransList = auctionTransRecordService.auctionTransRecordByUserId(userId);
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("auctionTransList", auctionTransList);
		return map;
	}
}
